package com.sugon.modules.report.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.map.MapUtil;
import com.sugon.dao.ModuleTimesRecordProdDao;
import com.sugon.modules.report.service.IMoldKpiComputeManager;
import com.sugon.service.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ： YuXD
 * @description： 模具KPI计算Manager实现类
 * @date ： 2021-01-19 下午 3:25
 * @version: 1.0
 */
@Service
public class MoldKpiComputeManagerImpl implements IMoldKpiComputeManager {

    @Autowired
    private SysConfigService configService;
    @Autowired
    private ModuleTimesRecordProdDao moduleTimesRecordProdDao;

    /**
     * doYearlyMoldProductTimeStat
     *
     * @param yearly   年度
     * @param moldCode 模具编码
     * @return
     */
    @Override
    public Map<Integer, Double> doYearlyMoldProductTimeStat(Integer yearly, String moldCode) {
        Map<Integer, Double> moldTimesYearlyStat = new LinkedHashMap<>();
        // 获取该模具节拍时间
        Double moldBeatTime = configService.getMoldBeatTime(moldCode);
        // 获取模具的年度模次统计
        // COLLECT_MONTH, SUM(MTR.TIMES) MOLD_TIMES
        List<Map<String, Object>> originalMoldTimesYearlyStatList = moduleTimesRecordProdDao.doMoldTimesYearlyStat(yearly, moldCode);
        if (CollectionUtil.isNotEmpty(originalMoldTimesYearlyStatList)) {
            for (Map<String, Object> originalMoldTimesYearlyStat : originalMoldTimesYearlyStatList) {
                moldTimesYearlyStat.put(MapUtil.getInt(originalMoldTimesYearlyStat, "COLLECT_MONTH"), MapUtil.getInt(originalMoldTimesYearlyStat, "MOLD_TIMES") * moldBeatTime);
            }
        }
        return moldTimesYearlyStat;
    }

}
